package com.myrslok.set;

import com.myrslok.util.FileUtil;
import org.jetbrains.annotations.NotNull;

import java.io.File;

public class CopyToFileAction implements ResourceSet.ResourceAction<File> {

    private final File toDir;
    private final File base;

    public CopyToFileAction(@NotNull final File toDir, @NotNull final File base) {
        this.toDir = toDir;
        this.base = base;
    }

    public CopyToFileAction(@NotNull final String toDir, @NotNull final String base) {
        this(new File(toDir), new File(base));
    }

    public CopyToFileAction(@NotNull final String toDir) {
        this.toDir = new File(toDir);
        this.base = null;
    }

    public CopyToFileAction(@NotNull final String toDir, @NotNull final File base) {
        this(new File(toDir), base);
    }

    @Override
    public void run(@NotNull final File f) {
        FileUtil.copyFile(f, new File(toDir, FileUtil.removeRoot(base, f).getPath()));
    }
    
}
